package fr.perso.spring.jmx;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.util.Assert;

public class RegisterService implements InitializingBean {

	private final Logger log = LoggerFactory.getLogger(RegisterService.class);

	private MBeanExporter mbeanExporter;

	private AnnotationTestBean jmxBean = null;

	public void afterPropertiesSet() throws Exception {

		jmxBean = new AnnotationTestBean();

		Assert.notNull(mbeanExporter, "mbeanExporter should not be null");
		mbeanExporter.registerManagedResource(jmxBean);
		log.warn("JmxBean registered.......");
		log.warn("Age:{} ", jmxBean.getAge());
		log.warn("Name:{} ", jmxBean.getName());

	}

	public MBeanExporter getMbeanExporter() {
		return mbeanExporter;
	}

	public void setMbeanExporter(MBeanExporter mbeanExporter) {
		this.mbeanExporter = mbeanExporter;
	}

	public AnnotationTestBean getJmxBean() {
		return jmxBean;
	}

	public String displayAge() {
		log.warn("Age:{} ", jmxBean.getAge());
		return "";
	}

	public String displayName() {
		log.warn("Name:{} ", jmxBean.getName());
		return "";
	}

}
